﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
//using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.Xml;
using System.IO;
using System.Collections;
using System.Diagnostics;
using System.Threading;
using System.Text.RegularExpressions;//正则表达式

using Xuhengxiao.MyDataStructure;

namespace Xuhengxiao.MediaConverter
{
    public partial class Form1 : Form
    {
        //
        XmlDocument configxml;//这个是配置的xml

        private delegate ListView.ListViewItemCollection getListViewItemCollection();
        
        struct ConvertData
        {
            public string strListViewItemTag;
            public string strParameter;//参数
            public ConvertData(string strtag, string strp)
            {
                strListViewItemTag = strtag;
                strParameter = strp;
            }

        }

        ArrayList alDuiLie;//这个存储要转换的文件的数据
        private delegate ConvertData getNextConvertData();//这个是取得下一个要转换数据的方法委托声明
        private delegate void setJinDu(string strTag,string strJinDu);//设置进度
        int intTag;//这个是设置listviewitem中的tag的

        clsXmlAppConfig currentclsXmlAppConfig=new clsXmlAppConfig();//当前的配置


        public Form1()
        {
            InitializeComponent();
            alDuiLie = new ArrayList();
            intTag = 1;

            //如果存在这个配置文件
            if (File.Exists("appConfig.xml"))
            {

                    currentclsXmlAppConfig = ClsXmlSerialization.Load<clsXmlAppConfig>("appConfig.xml");

                if (currentclsXmlAppConfig==null)
                {
                    currentclsXmlAppConfig = new clsXmlAppConfig();
                }
            }

            //如下是添加格式和配置列表框
            foreach (clsParameterOptionScheme item in currentclsXmlAppConfig.arrlistParameterOptionSchemes)
            {
                comboBoxAllFiletoFileFormat.Items.Add(item.FormatName);
                
            }

            foreach (clsParameter item in currentclsXmlAppConfig.arrlistParameters)
            {
                comboBoxUserSchemes.Items.Add(item.ParameterName);
            }

            loadUsersSchemes("3gp格式GSM手机");
            comboBoxUserSchemes.Text = "3gp格式GSM手机";


            /** 我用如上的序列化来实现XML
            //加载xml,加载可以转换成的格式
            if (File.Exists("config.xml"))
            {

                configxml = new XmlDocument();
                configxml.Load("config.xml");
                //添加支持的格式
                foreach (XmlElement xmlElementfmt in configxml.GetElementsByTagName("fmt"))
                {
                    //首先判断是否有已添加这种格式
                    string strTarget = xmlElementfmt.InnerText;

                    if (!(comboBoxAllFiletoFileFormat.Items.Contains(strTarget)))
                    {
                        //如果不存在就添加
                        comboBoxAllFiletoFileFormat.Items.Add(strTarget);
                        

                    }
                }

                //如下是添加自定义配置的。
                foreach (XmlElement xmlElementUserSchemeName in configxml.GetElementsByTagName("UserSchemeName"))
                {
                    comboBoxUserSchemes.Items.Add(xmlElementUserSchemeName.InnerText);
                }

            }
            else
            {
                MessageBox.Show("配置文件 config.xml 不存在，请重新安装或自己设置相关转化参数");
            }
             * */
        }

        ///这个软件主要有如下主要方法
        ///第一个方法是加载定义的转换格式配置，主要是像某个选项都有什么项目，是否禁用，是否可以让用户编辑的。
        ///第二个方法是加载和保存用户自定义的配置文件，包括转换成什么格式的，以及相关参数
        ///第三个方法是用户按转换按钮后，根据配置生成相关程序运行的参数，调用程序，并且读取程序输出，主要是进度。
        ///

        //根据文件格式加载相应的参数选项，这个由用户选择要转换哪种格式触发。
        public bool loadparameterOptionSchemes(string strFileFormat)
        {
            //判断是否加载了目录
            if (configxml == null)
                return false ;

            //判断是否有这种格式
            XmlElement xmlElementparameterOptionSchemes = (XmlElement)configxml.GetElementsByTagName("parameterOptionSchemes")[0];//我特定的他就是第一个

            foreach (XmlElement XmlElement1 in xmlElementparameterOptionSchemes.GetElementsByTagName("OptionItem"))
            {
                
                
                //特定的格式是第一个
                if (XmlElement1.GetElementsByTagName("fmt")[0].InnerText == strFileFormat)
                {
                    //到这里已经找到了想要的东西了。
                    //再加载每一项目参数
                    foreach (XmlElement xmlElementParameter in XmlElement1.GetElementsByTagName("Parameter"))
                    {
                        //下边这个就是根据转换目标的扩展名来判断了。
                        switch (xmlElementParameter.GetElementsByTagName("ParameterName")[0].InnerText )
                        {
                            //接下来就是分情况了，比如说尺寸，就向尺寸框内添加数据
                            case "-s size":
                                loadParameterTouserControlComboBox(xmlElementParameter, userControlComboBoxSSize);
                                break;
                            case "-ac channels":
                                loadParameterTouserControlComboBox(xmlElementParameter, userControlComboBoxAcChannels);
                                break;
                            case "-acodec codec":
                                loadParameterTouserControlComboBox(xmlElementParameter, userControlComboBoxAcodecCodec);
                                break;
                            case "-ar freq":
                                loadParameterTouserControlComboBox(xmlElementParameter, userControlComboBoxArFreq);
                                break;
                            case "-ab bitrate":
                                loadParameterTouserControlComboBox(xmlElementParameter,userControlComboBoxAbBitrate);
                                break;
                            case "-b bitrate":
                                loadParameterTouserControlComboBox(xmlElementParameter, userControlComboBoxBBitrate);
                                break;
                            case "-r fps":
                                loadParameterTouserControlComboBox(xmlElementParameter, userControlComboBoxRFps);
                                break;
                            case "-aspect aspect":
                                loadParameterTouserControlComboBox(xmlElementParameter, userControlComboBoxAspect);
                                break;
                            case "-bt tolerance":
                                loadParameterTouserControlComboBox(xmlElementParameter, userControlComboBoxBtTolerance);
                                break;
                            case "-maxrate bitrate":
                                loadParameterTouserControlComboBox(xmlElementParameter, userControlComboBoxMaxrateBitrate);
                                break;
                            case "-minrate bitreate":
                                loadParameterTouserControlComboBox(xmlElementParameter, userControlComboBoxMinrateBitreate);
                                break;
                            case "-bufsize size":
                                loadParameterTouserControlComboBox(xmlElementParameter,userControlComboBoxBufsizeSize);
                                break;
                            case "-vcodec codec":
                                loadParameterTouserControlComboBox(xmlElementParameter, userControlComboBoxVcodecCodec);
                                break;

                        }

                    }

                }

            }
            
            //如果到这里，说明没有找到相关格式
            return false ;

        }

        private void loadParameterTouserControlComboBox(clsParameterOptionSchemeItem cposi, UserControlComboBox myUserControlComboBox)
        {
            if ((cposi.ParameterValue!=null)&&(cposi.ParameterValue.Length>0))
            {
                foreach (string str in cposi.ParameterValue)
                {
                    myUserControlComboBox.Items.Add(str);
                }

            }
            if (cposi.isEdit)
            {
                //其他情况都是可编辑的
                myUserControlComboBox.DropDownStyle = ComboBoxStyle.DropDown;//这个就是可编辑的
            }
            else
            {
                myUserControlComboBox.DropDownStyle = ComboBoxStyle.DropDownList;//这个就是不可编辑的


            }
        }


        //如下一个仅仅是方便这个类的,作用是讲
        private void loadParameterTouserControlComboBox(XmlElement myxmlElementParameter, UserControlComboBox myUserControlComboBox)
        {


        }

        //加载用户选择的用户配置方案，参数有两个，第一个是用户配置名，第二个是目标格式。
        public bool loadUsersSchemes(string strUserSchemes,string strfmt)
        {
            XmlElement xmlElementUserSchemeItem=null ;//配置方案的根。
            //首先判断参数 strUserSchemes 是否不为空 ，如不为空直接获取相关参数就可以了，
            if (strUserSchemes != "")
            {
                foreach (XmlElement xmlElementUserSchemeName in configxml.GetElementsByTagName("UserSchemeName"))
                {
                    if (xmlElementUserSchemeName.InnerText == strUserSchemes)//如果找到这个名称的配置文件
                    {
                        xmlElementUserSchemeItem =(XmlElement) xmlElementUserSchemeName.ParentNode;//这个所要找的配置文件根就是这个配置名称的父节点
                        break;
                    }
                }

            }else if (strfmt !="")
            {
                //这个是自定义配置的根部
                XmlElement x1 = (XmlElement)configxml.GetElementsByTagName("UserSchemes")[0];
                foreach (XmlElement xmlElementfmt in x1.GetElementsByTagName("fmt"))//寻找自定义配置中是否有目标文件格式，如有，就说明有相关配置
                {
                    if (xmlElementfmt.InnerText == strfmt)
                    {
                        xmlElementUserSchemeItem = (XmlElement)xmlElementfmt.ParentNode;//等于它的父节点
                        break;
                    }
                }


            }else {
                return false ;//如果两个都为空，直接返回了。
            }

            //再判断是否找到了相关配置
            if (xmlElementUserSchemeItem == null)
            {
                return false;
            }

            clearParameter();//先清空

            //

            //先根据这个格式来更新相关参数 ，因为每个用户配置只能取一种目标格式，所以这里用[0]就可以了。
            if (xmlElementUserSchemeItem.GetElementsByTagName("fmt").Count==0)
                return false;

            string s1 = xmlElementUserSchemeItem.GetElementsByTagName("fmt")[0].InnerText;
            loadparameterOptionSchemes(s1);

            //如下是根据配置文件更新相关配置。
            //先设置目标文件
            comboBoxAllFiletoFileFormat.Text = xmlElementUserSchemeItem.GetElementsByTagName("fmt")[0].InnerText;
            comboBoxUserSchemes.Text = xmlElementUserSchemeItem.GetElementsByTagName("UserSchemeName")[0].InnerText;

            foreach (XmlElement xmlElementParameter in xmlElementUserSchemeItem.GetElementsByTagName("Parameter"))
            {
                switch (xmlElementParameter.GetElementsByTagName("ParameterName")[0].InnerText)
                {
                    //接下来就是分情况了，比如说尺寸，就讲相关控件设为相关数据
                    case "-s size":
                        userControlComboBoxSSize.Text = xmlElementParameter.GetElementsByTagName("ParameterValue")[0].InnerText;
                        break;
                    case "-ac channels":
                        userControlComboBoxAcChannels.Text = xmlElementParameter.GetElementsByTagName("ParameterValue")[0].InnerText;
                        break;
                    case "-acodec codec":
                        userControlComboBoxAcodecCodec.Text = xmlElementParameter.GetElementsByTagName("ParameterValue")[0].InnerText;
                        break;
                    case "-ar freq":
                        userControlComboBoxArFreq.Text = xmlElementParameter.GetElementsByTagName("ParameterValue")[0].InnerText;
                        break;
                    case "-ab bitrate":
                        userControlComboBoxAbBitrate.Text = xmlElementParameter.GetElementsByTagName("ParameterValue")[0].InnerText;
                        break;
                    case "-b bitrate":
                        userControlComboBoxBBitrate.Text = xmlElementParameter.GetElementsByTagName("ParameterValue")[0].InnerText;
                        break;
                    case "-r fps":
                        userControlComboBoxRFps.Text = xmlElementParameter.GetElementsByTagName("ParameterValue")[0].InnerText;
                        break;
                    case "-aspect aspect":
                        userControlComboBoxAspect.Text = xmlElementParameter.GetElementsByTagName("ParameterValue")[0].InnerText;
                        break;
                    case "-bt tolerance":
                        userControlComboBoxBtTolerance.Text = xmlElementParameter.GetElementsByTagName("ParameterValue")[0].InnerText;
                        break;
                    case "-maxrate bitrate":
                        userControlComboBoxMaxrateBitrate.Text = xmlElementParameter.GetElementsByTagName("ParameterValue")[0].InnerText;
                        break;
                    case "-minrate bitreate":
                        userControlComboBoxMinrateBitreate.Text = xmlElementParameter.GetElementsByTagName("ParameterValue")[0].InnerText;
                        break;
                    case "-bufsize size":
                        userControlComboBoxBufsizeSize.Text = xmlElementParameter.GetElementsByTagName("ParameterValue")[0].InnerText;
                        break;
                    case "-vcodec codec":
                        userControlComboBoxVcodecCodec.Text = xmlElementParameter.GetElementsByTagName("ParameterValue")[0].InnerText;
                        break;
                    
                }

            }

            //如果加载了相应的配置则返回真，否则返回假
            return true;

        }

        //保存用户
        public bool saveUsersSchemes(string strUserSchemes)
        {
            //如果成功保存则返回真，否则返回假
            return true;

        }

        //删除用户配置
        public bool deleteUsersSchemes(string strUserSchemes)
        {
            //如果成功删除则返回真，否则返回假
            return true;

        }

        private void button1_Click(object sender, EventArgs e)
        {

        }

        private void chkCaiJian_CheckedChanged(object sender, EventArgs e)
        {
            if (chkCaiJian.Checked == true)//如果选择裁剪，则这两个裁剪时间的才可以用。
            {
                txtSSPosition.ReadOnly = false;
                txtTDuration.ReadOnly = false;
            }
            else
            {
                txtTDuration.ReadOnly = true;
                txtSSPosition.ReadOnly = true;
            }
        }

        private void comboBoxAllFiletoFileFormat_SelectionChangeCommitted(object sender, EventArgs e)
        {

        }

        //转换操作

        //清空所有参数,只有在选择不同格式的时候采用这个操作，那个用户配置的只是选择其中一项而已,当然，那个会先调用相应格式的参数取值.
        private void clearParameter()
        {
                        
            txtSSPosition.Text = "";
            txtTDuration.Text = "";

            userControlComboBoxAbBitrate.clearComboData();
            userControlComboBoxAcChannels.clearComboData();
            userControlComboBoxAcodecCodec.clearComboData();
            userControlComboBoxArFreq.clearComboData();
            userControlComboBoxAspect.clearComboData();
            userControlComboBoxBBitrate.clearComboData();
            userControlComboBoxBtTolerance.clearComboData();
            userControlComboBoxBufsizeSize.clearComboData();
            userControlComboBoxMaxrateBitrate.clearComboData();
            userControlComboBoxMinrateBitreate.clearComboData();
            userControlComboBoxRFps.clearComboData();
            userControlComboBoxSSize.clearComboData();
            userControlComboBoxVcodecCodec.clearComboData();

            userControlComboBoxAbBitrate.Text="";
            userControlComboBoxAcChannels.Text = "";
            userControlComboBoxAcodecCodec.Text = "";
            userControlComboBoxArFreq.Text = "";
            userControlComboBoxAspect.Text = "";
            userControlComboBoxBBitrate.Text = "";
            userControlComboBoxBtTolerance.Text = "";
            userControlComboBoxBufsizeSize.Text = "";
            userControlComboBoxMaxrateBitrate.Text = "";
            userControlComboBoxMinrateBitreate.Text = "";
            userControlComboBoxRFps.Text = "";
            userControlComboBoxSSize.Text = "";
            userControlComboBoxVcodecCodec.Text = "";

            chkCaiJian.Checked = false;
            chkAn.Checked = false;
            chkSameq.Checked = false;
            chkVn.Checked = false;


        }

        private void comboBoxAllFiletoFileFormat_TextUpdate(object sender, EventArgs e)
        {
            //如果支持这个目标格式，则也显示相应参数
            if (comboBoxAllFiletoFileFormat.Items.Contains(comboBoxAllFiletoFileFormat.Text))
            {
                clearParameter();//先清空
                loadparameterOptionSchemes(comboBoxAllFiletoFileFormat.Text);//再加载
                comboBoxUserSchemes.Text = "";//现将自定义配置设置
                loadUsersSchemes("", comboBoxAllFiletoFileFormat.Text);//再查看是否有相关格式的用户配置。   
                comboBoxAllFiletoFileFormat.Text = comboBoxAllFiletoFileFormat.Text;
            }
        }

        private void comboBoxAllFiletoFileFormat_SelectedIndexChanged(object sender, EventArgs e)
        {
            clearParameter();//先清空
            loadparameterOptionSchemes(comboBoxAllFiletoFileFormat.Text);//再加载
            comboBoxUserSchemes.Text = "";//现将自定义配置设置
            loadUsersSchemes("", comboBoxAllFiletoFileFormat.Text);//再查看是否有相关格式的用户配置。


        }

        private void btnLoadUserSchemes_Click(object sender, EventArgs e)
        {
            loadUsersSchemes(comboBoxUserSchemes.Text,"");

        }

        private void btnSaveUserSchemes_Click(object sender, EventArgs e)
        {
            XmlElement xmlElementUserSchemeItem = null;
            

            //保存配置操作首先看看配置原先有没有。
            foreach (XmlElement xmlElementUserSchemeName in configxml.GetElementsByTagName("UserSchemeName"))
            {
                if (xmlElementUserSchemeName.InnerText == comboBoxUserSchemes.Text)
                {
                    xmlElementUserSchemeItem = (XmlElement)xmlElementUserSchemeName.ParentNode;//等于它的父类
                   
                }
            }

            //如果不存在就新建一个.
            if (xmlElementUserSchemeItem == null)
            {
                xmlElementUserSchemeItem = configxml.CreateElement("UserSchemeItem");//先创建一个
                ((XmlElement)configxml.GetElementsByTagName("UserSchemes")[0]).AppendChild(xmlElementUserSchemeItem); //再加到xml中
            }
            else
            {
                //删除原先的，这个不能在 GetElementsByTagName 遍历中修改。
                xmlElementUserSchemeItem.RemoveAll();
            }

            //接下来保存用户配置名称。
            XmlElement xmlElement1 = configxml.CreateElement("UserSchemeName");
            XmlNode xmlNode1 = configxml.CreateTextNode(comboBoxUserSchemes.Text);
            xmlElementUserSchemeItem.AppendChild(xmlElement1);
            xmlElement1.AppendChild(xmlNode1);

            //接下来保存用户格式
            XmlElement xmlElement2 = configxml.CreateElement("fmt");
            XmlNode xmlNode2 = configxml.CreateTextNode(comboBoxAllFiletoFileFormat.Text);
            xmlElementUserSchemeItem.AppendChild(xmlElement2);
            xmlElement2.AppendChild(xmlNode2);



            //接下来是具体保存工作。每个都是不等于空才保存
            saveComboBoxTextUserSchemeToXml(xmlElementUserSchemeItem, "-s size", userControlComboBoxSSize.Text);
            saveComboBoxTextUserSchemeToXml(xmlElementUserSchemeItem, "-ac channels", userControlComboBoxAcChannels.Text);
            saveComboBoxTextUserSchemeToXml(xmlElementUserSchemeItem, "-acodec codec", userControlComboBoxAcodecCodec.Text);
            saveComboBoxTextUserSchemeToXml(xmlElementUserSchemeItem, "-ar freq", userControlComboBoxArFreq.Text);
            saveComboBoxTextUserSchemeToXml(xmlElementUserSchemeItem, "-ab bitrate", userControlComboBoxAbBitrate.Text);
            saveComboBoxTextUserSchemeToXml(xmlElementUserSchemeItem, "-b bitrate", userControlComboBoxBBitrate.Text);
            saveComboBoxTextUserSchemeToXml(xmlElementUserSchemeItem, "-r fps", userControlComboBoxRFps.Text);
            saveComboBoxTextUserSchemeToXml(xmlElementUserSchemeItem, "-aspect aspect", userControlComboBoxAspect.Text);
            saveComboBoxTextUserSchemeToXml(xmlElementUserSchemeItem, "-bt tolerance", userControlComboBoxBtTolerance.Text);
            saveComboBoxTextUserSchemeToXml(xmlElementUserSchemeItem, "-maxrate bitrate", userControlComboBoxMaxrateBitrate.Text);
            saveComboBoxTextUserSchemeToXml(xmlElementUserSchemeItem, "-minrate bitreate", userControlComboBoxMinrateBitreate.Text);
            saveComboBoxTextUserSchemeToXml(xmlElementUserSchemeItem, "-bufsize size", userControlComboBoxBufsizeSize.Text);
            saveComboBoxTextUserSchemeToXml(xmlElementUserSchemeItem, "-vcodec codec", userControlComboBoxVcodecCodec.Text);

            configxml.Save(AppDomain.CurrentDomain.BaseDirectory+ "config.xml");

            //检查以下这个这个项目原先有没有
            if (!comboBoxUserSchemes.Items.Contains(comboBoxUserSchemes.Text))
            {
                comboBoxUserSchemes.Items.Add(comboBoxUserSchemes.Text);
            }

        }

        //这个是添加每一项到相关XML中，有三个参数，第一个UserSchemeItem,第二个为strParameterName,第三个参数strParameterValue
        private void saveComboBoxTextUserSchemeToXml(XmlElement myxmlElementUserSchemeItem, string strParameterName, string strParameterValue)
        {
            if (strParameterValue != "")
            {

                XmlElement xmlElementParameter = configxml.CreateElement("Parameter");
                myxmlElementUserSchemeItem.AppendChild(xmlElementParameter);

                XmlElement xmlElementParameterName = configxml.CreateElement("ParameterName");
                XmlNode xmlNode1 = configxml.CreateTextNode(strParameterName);
                xmlElementParameter.AppendChild(xmlElementParameterName);
                xmlElementParameterName.AppendChild(xmlNode1);

                XmlElement xmlElementParameterValue = configxml.CreateElement("ParameterValue");
                XmlNode xmlNode2 = configxml.CreateTextNode(strParameterValue);
                xmlElementParameter.AppendChild(xmlElementParameterValue);
                xmlElementParameterValue.AppendChild(xmlNode2);
            }

        }

        private void btnDeleteUserSchemes_Click(object sender, EventArgs e)
        {
             XmlElement xmlElementUserSchemeItem=null;

            //保存配置操作首先看看配置原先有没有。
            foreach (XmlElement xmlElementUserSchemeName in configxml.GetElementsByTagName("UserSchemeName"))
            {
                if (xmlElementUserSchemeName.InnerText == comboBoxUserSchemes.Text)
                {
                    xmlElementUserSchemeItem = (XmlElement)xmlElementUserSchemeName.ParentNode;//等于它的父节点

                    break;
                }
            }

            if (xmlElementUserSchemeItem != null)
            {
                configxml.GetElementsByTagName("UserSchemes")[0].RemoveChild(xmlElementUserSchemeItem);
                configxml.Save(AppDomain.CurrentDomain.BaseDirectory+"config.xml");
            }

            //既然这个已经被删除了，就为空吧。
            comboBoxUserSchemes.Items.Remove(comboBoxUserSchemes.Text);
            comboBoxUserSchemes.Text = "";

        }

        private void btnAddFile_Click(object sender, EventArgs e)
        {
            //就是打开一个文件对话框。
            openFileDialog1.ShowDialog();

            //取得用户选择的文件列表后，加入listview空间中.
            foreach (string strFilePath in openFileDialog1.FileNames)
            {
                ListViewItem myListViewItem = new ListViewItem();
               
                //暂时给他选择两个项目，一个是路径，一个是格式，但其他列也全部定义上.
                ListViewItem.ListViewSubItem ListViewSubItemFilePath = new ListViewItem.ListViewSubItem();
                ListViewSubItemFilePath.Name = "filePath";
                ListViewSubItemFilePath.Text = strFilePath;
                myListViewItem.SubItems.Add(ListViewSubItemFilePath);

                //格式
                ListViewItem.ListViewSubItem ListViewSubItemOldFileFormat = new ListViewItem.ListViewSubItem();
                ListViewSubItemOldFileFormat.Name = "OldFileFormat";
                ListViewSubItemOldFileFormat.Text = Path.GetExtension(strFilePath);
                myListViewItem.SubItems.Add(ListViewSubItemOldFileFormat);

                //转换成格式
                ListViewItem.ListViewSubItem ListViewSubItemfmt = new ListViewItem.ListViewSubItem();
                ListViewSubItemfmt.Name = "fmt";
                myListViewItem.SubItems.Add(ListViewSubItemfmt);

                //开始时间
                ListViewItem.ListViewSubItem ListViewSubItemKaiShiShiJian = new ListViewItem.ListViewSubItem();
                ListViewSubItemKaiShiShiJian.Name = "KaiShiShiJian";
                myListViewItem.SubItems.Add(ListViewSubItemKaiShiShiJian);

                //结束时间
                ListViewItem.ListViewSubItem ListViewSubItemJieShuShiJian = new ListViewItem.ListViewSubItem();
                ListViewSubItemJieShuShiJian.Name = "JieShuShiJian";
                myListViewItem.SubItems.Add(ListViewSubItemJieShuShiJian);

                //进度
                ListViewItem.ListViewSubItem ListViewSubItemJinDu = new ListViewItem.ListViewSubItem();
                ListViewSubItemJinDu.Name = "JinDu";
                myListViewItem.SubItems.Add(ListViewSubItemJinDu);

                //设置tag
                myListViewItem.Tag = intTag.ToString();
                intTag = intTag + 1;

                

                listView1.Items.Add(myListViewItem);
                
            }

        }


        //以下是从http://www.ffmpeg.com.cn 抄归来的。
        public void ConvertVideo (string strCmd, string strParameter)
        {
            //我这个方法的参数为文件，默认就是处理单个文件的。
            

            Process p = new Process();//建立外部调用线程

            p.StartInfo.FileName = strCmd;//要调用外部程序的绝对路径

            p.StartInfo.Arguments = strParameter;//参数(这里就是FFMPEG的参数了)
            p.StartInfo.UseShellExecute = false;//不使用操作系统外壳程序启动线程(一定为FALSE,详细的请看MSDN)
            p.StartInfo.RedirectStandardError = true;//把外部程序错误输出写到StandardError流中(这个一定要注意,FFMPEG的所有输出信息,都为错误输出流,用StandardOutput是捕获不到任何消息的...这是我耗费了2个多月得出来的经验...mencoder就是用standardOutput来捕获的)
            
            p.StartInfo.CreateNoWindow = true ;//不创建进程窗口,原文这个错了。

            p.Start();//启动线程
            //p.BeginErrorReadLine();//开始异步读取

            StreamReader reader = p.StandardError;

            while (!reader.EndOfStream)
            {
               
            }


            p.WaitForExit();//阻塞等待进程结束

            p.Close();//关闭进程
            p.Dispose();//释放资源


        }




        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Process.Start("mailto:kerwin.cn@gmail.com");
        }

        //生成命令行参数字符串,根据文件名位置和相关控件的值生成字符串
        private string createStrParameter(string strFilePath)
        {
            string strParameter = "";
            string strTemp = "";

            //获取文件名
            strParameter = strParameter + " -i " + "\"" + strFilePath + "\"";//输入文件加上双引号 "，以便目录或者文件名有空格的时候不被断开 

            //起始时间
            if ((txtTDuration.Enabled == true) && (txtTDuration.Text != ""))
            {
                strTemp = txtTDuration.Text.Replace("：", ":").Replace(" ","");//讲英文状态的转换成中文状态的.和消除任何空白
                strParameter = strParameter+"  -t   " + strTemp;
            }

            //录制时间
            if ((txtSSPosition.Enabled == true) && (txtSSPosition.Text != ""))
            {
                strTemp = txtSSPosition.Text.Replace("：", ":").Replace(" ", "");//讲英文状态的转换成中文状态的.和消除任何空白
                strParameter = strParameter + "  -ss   " + strTemp;
            }

            //转化成格式 
            strParameter = strParameter + " -f " + comboBoxAllFiletoFileFormat.Text;



            //判断是否录音频
            if (chkAn.Checked == false)
            {
                foreach (Control mycontrol in flowLayoutPanel1.Controls)
                {
                    if (mycontrol.GetType().ToString() == "万能媒体转换器.UserControlComboBox")
                    {

                        if ((mycontrol.Enabled) && (((UserControlComboBox)mycontrol).Text != "") && (((UserControlComboBox)mycontrol).Text != "自动"))
                            strParameter = strParameter + " " + ((UserControlComboBox)mycontrol).Tag + " " + ((UserControlComboBox)mycontrol).Text;
                    }
                }

            }
            else
            {
                strParameter = strParameter + " -an ";
            }

            //判断是否录视频
            if (chkVn.Checked == false)
            {
                foreach (Control mycontrol in flowLayoutPanel2.Controls)
                {
                    if (mycontrol.GetType().ToString() == "万能媒体转换器.UserControlComboBox")
                    {
                        if ((mycontrol.Enabled) && (((UserControlComboBox)mycontrol).Text != "") && (((UserControlComboBox)mycontrol).Text != "自动"))
                            strParameter = strParameter + " " + ((UserControlComboBox)mycontrol).Tag + " " + ((UserControlComboBox)mycontrol).Text;
                    }
                }

                if ((userControlComboBoxVcodecCodec.Enabled) && (userControlComboBoxVcodecCodec.Text != "") && (userControlComboBoxVcodecCodec.Text != "自动"))
                    strParameter = strParameter + " " + userControlComboBoxVcodecCodec.Tag + " " + userControlComboBoxVcodecCodec.Text;

                if (chkSameq.Checked)
                    strParameter = strParameter + " -sameq ";

            }
            else
            {
                strParameter = strParameter + " -vn ";
            }

            //关于输出文件名，这个软件会自动判断是否有同名文件，如有，这个输出文件就重命名。
            //listView1.Items[intIndex].SubItems[listView1.Items[intIndex].SubItems.IndexOfKey("filePath")].Text
            //判断目录

            string strdir = "";
            if (chkSaveOldDir.Checked)
            {
                strdir = Path.GetDirectoryName(strFilePath);
            }
            else
            {
                strdir = txtDir.Text;
            }

            //if ((strdir.EndsWith("\\")))
            strdir = strdir + "\\";

            //取得文件名,不算扩展名
            string strF = Path.GetFileNameWithoutExtension(strFilePath);
            string strTarget = strdir + strF + "." + comboBoxAllFiletoFileFormat.Text;
            int i = 1;
            while (File.Exists(strTarget))
            {
                //如果存在就重命名
                strTarget = strdir + strF +"-"+ i.ToString() + "." + comboBoxAllFiletoFileFormat.Text;
                i = i + 1;
            }

            strParameter = strParameter + " \"" + strTarget + "\"";
                

            //将目标文件名加到参数中
            
            strParameter = strParameter.Replace(@"\\", @"\");

            //返回总的参数
            return strParameter;


        }

        private void btnDeleteFile_Click(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count > 0)
            {
                foreach (ListViewItem lvt in listView1.SelectedItems)
                {
                    listView1.Items.Remove(lvt);
                }
            }
        }

        private void chkAn_CheckedChanged(object sender, EventArgs e)
        {
            if (chkAn.Checked == true)
            {
                foreach (Control mycontrol in groupBox4.Controls[0].Controls)
                {
                    if (mycontrol.GetType().ToString() == "万能媒体转换器.UserControlComboBox")
                    {
                        mycontrol.Enabled = false;
                    }

                }

            }
            else
            {
                foreach (Control mycontrol in groupBox4.Controls[0].Controls)
                {
                    if (mycontrol.GetType().ToString() == "万能媒体转换器.UserControlComboBox")
                    {
                        mycontrol.Enabled = true;
                    }

                }

            }
        }

        private void chkVn_CheckedChanged(object sender, EventArgs e)
        {
            if (chkVn.Checked == true)
            {
                foreach (Control mycontrol in flowLayoutPanel2.Controls)
                {
                    if (mycontrol.GetType().ToString() == "万能媒体转换器.UserControlComboBox")
                    {
                        mycontrol.Enabled = false;

                    }

                }

                //还有两个漏网之鱼
                userControlComboBoxVcodecCodec.Enabled = false;
                chkSameq.Enabled = false;

            }
            else
            {
                foreach (Control mycontrol in flowLayoutPanel2.Controls)
                {
                    if (mycontrol.GetType().ToString() == "万能媒体转换器.UserControlComboBox")
                    {
                        mycontrol.Enabled = true;
                    }

                }

                //还有两个漏网之鱼
                userControlComboBoxVcodecCodec.Enabled = true;
                chkSameq.Enabled = true ;

            }

        }

        private void chkSameq_CheckedChanged(object sender, EventArgs e)
        {
            if (chkSameq.Checked == true)
            {
                foreach (Control mycontrol in flowLayoutPanel2.Controls)
                {
                    if (mycontrol.GetType().ToString() == "万能媒体转换器.UserControlComboBox")
                    {
                        mycontrol.Enabled = false;

                    }

                }

            }
            else
            {
                foreach (Control mycontrol in flowLayoutPanel2.Controls)
                {
                    if (mycontrol.GetType().ToString() == "万能媒体转换器.UserControlComboBox")
                    {
                        mycontrol.Enabled = true;
                    }

                }

            }

        }

        private void btnFileConvert_Click(object sender, EventArgs e)
        {
            //将这些列表都加载到队列中
            foreach (ListViewItem lvi in listView1.SelectedItems)
            {

                ConvertData myconvertdate = new ConvertData(lvi.Tag.ToString(), createStrParameter(lvi.SubItems[lvi.SubItems.IndexOfKey("filePath")].Text));
                alDuiLie.Add(myconvertdate);//添加到队列中

                //设置相关信息
                lvi.SubItems[lvi.SubItems.IndexOfKey("fmt")].Text = comboBoxAllFiletoFileFormat.Text;
                lvi.SubItems[lvi.SubItems.IndexOfKey("KaiShiShiJian")].Text = txtSSPosition.Text;
                lvi.SubItems[lvi.SubItems.IndexOfKey("JieShuShiJian")].Text = txtTDuration.Text; 
                lvi.SubItems[lvi.SubItems.IndexOfKey("JinDu")].Text = "初始化转换";

            }

            //开始转换线程，有转换线程负责转换过程。
            Thread threadZhuanHuan = new Thread(new ThreadStart(FFmpegThread));
            threadZhuanHuan.Start();
        }

        private void chkSaveOldDir_CheckedChanged(object sender, EventArgs e)
        {
            if (chkSaveOldDir.Checked)
            {
                txtDir.Enabled = false;
                btnSelectDir.Enabled = false;
            }
            else
            {
                txtDir.Enabled = true;
                btnSelectDir.Enabled = true;
            }
        }

        private void btnSelectDir_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1.ShowDialog();
            txtDir.Text = folderBrowserDialog1.SelectedPath;
        }

        private void btnJiaZaiCanShu_Click(object sender, EventArgs e)
        {
            //如果支持这个目标格式，则也显示相应参数
            if (comboBoxAllFiletoFileFormat.Items.Contains(comboBoxAllFiletoFileFormat.Text))
            {
                clearParameter();//先清空
                loadparameterOptionSchemes(comboBoxAllFiletoFileFormat.Text);//再加载
                comboBoxUserSchemes.Text = "";//现将自定义配置设置
                loadUsersSchemes("", comboBoxAllFiletoFileFormat.Text);//再查看是否有相关格式的用户配置。   
                comboBoxAllFiletoFileFormat.Text = comboBoxAllFiletoFileFormat.Text;
            }
        }

        private void btnAllFileConvert_Click(object sender, EventArgs e)
        {
            //将这些列表都加载到队列中
            foreach (ListViewItem lvi in listView1.Items)
            {

                //ConvertData myconvertdate = new ConvertData(lvi.Tag.ToString(), createStrParameter(lvi.SubItems[lvi.SubItems.IndexOfKey("filePath")].Text));
                ConvertData myconvertdate = new ConvertData(lvi.Tag.ToString(), getUserSchems(lvi.SubItems[lvi.SubItems.IndexOfKey("filePath")].Text).createParameter());
                alDuiLie.Add(myconvertdate);//添加到队列中

                //设置相关信息
                lvi.SubItems[lvi.SubItems.IndexOfKey("fmt")].Text = comboBoxAllFiletoFileFormat.Text;
                lvi.SubItems[lvi.SubItems.IndexOfKey("KaiShiShiJian")].Text = txtSSPosition.Text;
                lvi.SubItems[lvi.SubItems.IndexOfKey("JieShuShiJian")].Text = txtTDuration.Text; 
                lvi.SubItems[lvi.SubItems.IndexOfKey("JinDu")].Text = "初始化转换";

            }

            //开始转换线程，有转换线程负责转换过程。
            Thread threadZhuanHuan = new Thread(new ThreadStart(FFmpegThread));
            threadZhuanHuan.Start();

        }


        private void FFmpegThread()
        {
            ///这个线程有些操作得异步操作
            ///步骤
            ///首先取得下一个执行的相关信息,这个信息是一个结构，包含数据有listviewitem.tag，命令参数，如为空，这个线程就结束了。
            ///再调用 ffmpeg 线程，并截断错误流
            ///将进度更新到listview 控件中.
            ///

            while (true)
            {
                ConvertData ConvertData1 = (ConvertData)this.Invoke(new getNextConvertData(mygetNextConvertData));//取得下一项数据
                //判断下一项是否为空
                if (ConvertData1.strListViewItemTag == "")
                    return;

                //开始执行外部程序线程
                Process p = new Process();//建立外部调用线程
                p.StartInfo.FileName = @"ffmpeg\ffmpeg.exe";//要调用外部程序的绝对路径
                p.StartInfo.Arguments = ConvertData1.strParameter;//参数(这里就是FFMPEG的参数了)
                p.StartInfo.UseShellExecute = false;//不使用操作系统外壳程序启动线程(一定为FALSE,详细的请看MSDN)
                p.StartInfo.RedirectStandardError = true;//把外部程序错误输出写到StandardError流中(这个一定要注意,FFMPEG的所有输出信息,都为错误输出流,用StandardOutput是捕获不到任何消息的...这是我耗费了2个多月得出来的经验...mencoder就是用standardOutput来捕获的)
                p.StartInfo.CreateNoWindow = true;//不创建进程窗口,原文这个错了。
                
                p.Start();//启动线程
                //p.BeginErrorReadLine();//开始异步读取

                StreamReader reader = p.StandardError;
                Regex regexTime = new Regex(@"time=(?<time>[\d\.]*)");//匹配时间的正则表达式
                bool boolZhuanHuanOk = false;
                while (!reader.EndOfStream)
                {
                    string strLine = reader.ReadLine();//返回一行输出数据
                    
                    //正则匹配出时间
                    if (regexTime.IsMatch(strLine))
                    {
                        Match m = regexTime.Match(strLine);
                        string strTime = m.Groups["time"].Value+"秒";
                        if (strTime.Contains("000000000.00"))
                        {
                            this.Invoke(new setJinDu(mySetJinDu), new object[] { ConvertData1.strListViewItemTag, "搜索时间中" });
                            continue;//下一循环
                        }
                        this.Invoke(new setJinDu(mySetJinDu), new object[] { ConvertData1.strListViewItemTag, strTime });
                        continue;//下一循环
                    }
                    
                    //判断是否结束了
                    if (strLine.Contains("global headers"))
                    {
                        boolZhuanHuanOk = true;
                        this.Invoke(new setJinDu(mySetJinDu), new object[] { ConvertData1.strListViewItemTag, "已转换完成" });
                    }

                }

                if (boolZhuanHuanOk == false)
                {
                    this.Invoke(new setJinDu(mySetJinDu), new object[] { ConvertData1.strListViewItemTag, "转换不成功" });
                }

                //如下的就是释放资源了
                reader.Close();
                //p.WaitForExit();//阻塞等待进程结束
                p.Close();//关闭进程
                p.Dispose();//释放资源

            }

        }


        //这个方法取得要转换的下一个文件的数据的实现
        private ConvertData mygetNextConvertData()
        {
            ConvertData ConvertData1 = new ConvertData("","");

            if (alDuiLie.Count > 0)
            {
                ConvertData1 = (ConvertData)alDuiLie[0];
                alDuiLie.Remove(ConvertData1);//直接删除这一项，不管成不成功

            }

            return ConvertData1;

        }

        //设置进度实现
        private void mySetJinDu(string strTag,string strJinDu)
        {
            foreach (ListViewItem lvi in listView1.Items)
            {
                if (lvi.Tag.ToString() == strTag)
                {
                    lvi.SubItems[lvi.SubItems.IndexOfKey("JinDu")].Text =strJinDu;
                    return;
                }
            }

        }

        /// <summary>
        /// 加载配置
        /// </summary>
        /// <param name="str"></param>
        private void loadUsersSchemes(string str)
        {

            //判断是那个配置
            foreach (clsParameter item in currentclsXmlAppConfig.arrlistParameters)
            {
                if (item.ParameterName==str)
                {

                    //然后加载格式
                    loadFormatParameter(item.FormatName);

                    //然后加载配置
                    comboBoxAllFiletoFileFormat.Text = item.FormatName;

                    userControlComboBoxSSize.Text = item.SSzie;
                    userControlComboBoxAcChannels.Text = item.AcChannels;
                    userControlComboBoxAcodecCodec.Text = item.AcCodecCodec;
                    userControlComboBoxArFreq.Text = item.ArFreq;
                    userControlComboBoxAbBitrate.Text = item.AbBitRate;
                    userControlComboBoxBBitrate.Text = item.BBitRate;
                    userControlComboBoxRFps.Text = item.RFps;
                    userControlComboBoxAspect.Text = item.AsPect;
                    userControlComboBoxBtTolerance.Text = item.BtTolerance;
                    userControlComboBoxMaxrateBitrate.Text = item.MaxrateBitrate;
                    userControlComboBoxMinrateBitreate.Text = item.MinrateBitrate;
                    userControlComboBoxBufsizeSize.Text = item.BufSize;
                    userControlComboBoxVcodecCodec.Text = item.VCodecCodec;

                    chkAn.Checked = !item.isAC;
                    chkVn.Checked = !item.isVn;
                    chkSameq.Checked = item.sameQ;
                }
                
            }




        }

        /// <summary>
        /// 加载格式配置
        /// </summary>
        /// <param name="strFormatName"></param>
        private void loadFormatParameter(string strFormatName)
        {

            foreach (clsParameterOptionScheme item in currentclsXmlAppConfig.arrlistParameterOptionSchemes)
            {
                if (item.FormatName==strFormatName)
                {
                    //接下来就是分情况了，比如说尺寸，就向尺寸框内添加数据
                    loadParameterTouserControlComboBox(item.SSize, userControlComboBoxSSize);
                    loadParameterTouserControlComboBox(item.AcChannels, userControlComboBoxAcChannels);
                    loadParameterTouserControlComboBox(item.AcodecCodec, userControlComboBoxAcodecCodec);
                    loadParameterTouserControlComboBox(item.ArFreq, userControlComboBoxArFreq);
                    loadParameterTouserControlComboBox(item.AbBitrate, userControlComboBoxAbBitrate);
                    loadParameterTouserControlComboBox(item.BBitrate, userControlComboBoxBBitrate);
                    loadParameterTouserControlComboBox(item.RFps, userControlComboBoxRFps);
                    loadParameterTouserControlComboBox(item.AspectAspect, userControlComboBoxAspect);
                    loadParameterTouserControlComboBox(item.BtTolerance, userControlComboBoxBtTolerance);
                    loadParameterTouserControlComboBox(item.MaxrateBitrate, userControlComboBoxMaxrateBitrate);
                    loadParameterTouserControlComboBox(item.MinrateBitreate, userControlComboBoxMinrateBitreate);
                    loadParameterTouserControlComboBox(item.BufsizeSize, userControlComboBoxBufsizeSize);
                    loadParameterTouserControlComboBox(item.VcodecCodec, userControlComboBoxVcodecCodec);

                    
                    return;
                    

                }
            }

            

        }

        /// <summary>
        /// 取得配置
        /// </summary>
        /// <returns></returns>
        private clsParameter getUserSchems(string strFilePath)
        {
            clsParameter clsParameterReturn = new clsParameter();

            clsParameterReturn.FormatName = comboBoxAllFiletoFileFormat.Text;
            clsParameterReturn.SSzie = userControlComboBoxSSize.Text;
            clsParameterReturn.AcChannels = userControlComboBoxAcChannels.Text;
            clsParameterReturn.AcCodecCodec = userControlComboBoxAcodecCodec.Text;
            clsParameterReturn.ArFreq = userControlComboBoxArFreq.Text;
            clsParameterReturn.AbBitRate = userControlComboBoxAbBitrate.Text;
            clsParameterReturn.BBitRate = userControlComboBoxBBitrate.Text;
            clsParameterReturn.RFps = userControlComboBoxRFps.Text;
            clsParameterReturn.AsPect = userControlComboBoxAspect.Text;
            clsParameterReturn.BtTolerance = userControlComboBoxBtTolerance.Text;
            clsParameterReturn.MaxrateBitrate = userControlComboBoxMaxrateBitrate.Text;
            clsParameterReturn.MinrateBitrate = userControlComboBoxMinrateBitreate.Text;
            clsParameterReturn.BufSize = userControlComboBoxBufsizeSize.Text;
            clsParameterReturn.VCodecCodec = userControlComboBoxVcodecCodec.Text;
            clsParameterReturn.isAC = !chkAn.Checked;
            clsParameterReturn.isVn = !chkVn.Checked;
            clsParameterReturn.sameQ = chkSameq.Checked;

            clsParameterReturn.sourcePath = strFilePath;

            //目标路径
            //关于输出文件名，这个软件会自动判断是否有同名文件，如有，这个输出文件就重命名。
            //listView1.Items[intIndex].SubItems[listView1.Items[intIndex].SubItems.IndexOfKey("filePath")].Text
            //判断目录

            string strdir = "";
            if (chkSaveOldDir.Checked)
            {
                strdir = Path.GetDirectoryName(strFilePath);
            }
            else
            {
                strdir = txtDir.Text;
            }

            //if ((strdir.EndsWith("\\")))
            strdir = strdir + "\\";

            //取得文件名,不算扩展名
            string strF = Path.GetFileNameWithoutExtension(strFilePath);
            string strTarget = strdir + strF + "." + comboBoxAllFiletoFileFormat.Text;
            int i = 1;
            while (File.Exists(strTarget))
            {
                //如果存在就重命名
                strTarget = strdir + strF + "-" + i.ToString() + "." + comboBoxAllFiletoFileFormat.Text;
                i = i + 1;
            }

            clsParameterReturn.destPath= strTarget;


            clsParameterReturn.isCut = chkCaiJian.Checked;
            //录制时间
            if ((txtTDuration.Enabled == true) && (txtTDuration.Text != ""))
            {
                clsParameterReturn.TDuration = txtTDuration.Text.Replace("：", ":").Replace(" ", "");//讲英文状态的转换成中文状态的.和消除任何空白
            }

            //开始时间
            if ((txtSSPosition.Enabled == true) && (txtSSPosition.Text != ""))
            {
                clsParameterReturn.SSPosition = txtSSPosition.Text.Replace("：", ":").Replace(" ", "");//讲英文状态的转换成中文状态的.和消除任何空白
            }


            return clsParameterReturn;

        }


        private void comboBoxUserSchemes_SelectionChangeCommitted(object sender, EventArgs e)
        {
            clearParameter();
            loadUsersSchemes(comboBoxUserSchemes.SelectedItem.ToString());
        }


        private void btnZhuanHuanSuoYouWeiWanCheng_Click(object sender, EventArgs e)
        {
            //将这些列表都加载到队列中
            foreach (ListViewItem lvi in listView1.Items)
            {
                //进度为空的就转换
                if (lvi.SubItems[lvi.SubItems.IndexOfKey("JinDu")].Text == "")
                {
                    ConvertData myconvertdate = new ConvertData(lvi.Tag.ToString(), createStrParameter(lvi.SubItems[lvi.SubItems.IndexOfKey("filePath")].Text));
                    alDuiLie.Add(myconvertdate);//添加到队列中

                    //设置相关信息
                    lvi.SubItems[lvi.SubItems.IndexOfKey("fmt")].Text = comboBoxAllFiletoFileFormat.Text;
                    lvi.SubItems[lvi.SubItems.IndexOfKey("KaiShiShiJian")].Text = txtSSPosition.Text;
                    lvi.SubItems[lvi.SubItems.IndexOfKey("JieShuShiJian")].Text = txtTDuration.Text; 
                    lvi.SubItems[lvi.SubItems.IndexOfKey("JinDu")].Text = "初始化转换";
                }

            }

            //开始转换线程，有转换线程负责转换过程。
            Thread threadZhuanHuan = new Thread(new ThreadStart(FFmpegThread));
            threadZhuanHuan.Start();
        }

        private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            System.Diagnostics.Process.Start("http://xuhengxiao.taobao.com/");
        }

        private void comboBoxAllFiletoFileFormat_SelectionChangeCommitted_1(object sender, EventArgs e)
        {
            clearParameter();
            loadFormatParameter(comboBoxAllFiletoFileFormat.SelectedItem.ToString());
            //判断这个格式是否有相关的配置
            foreach (clsParameter item in currentclsXmlAppConfig.arrlistParameters)
            {
                //如果有这种格式的配置
                if (item.FormatName==comboBoxAllFiletoFileFormat.SelectedItem.ToString())
                {
                    //就加载这种配置
                    comboBoxUserSchemes.Text = item.ParameterName;
                    loadUsersSchemes(item.ParameterName);
                    return;
                }
                
            }

            //如下的就是单纯的加载配置，并清空
            comboBoxUserSchemes.Text = "";
            
        }

        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            //关闭后保存配置
            ClsXmlSerialization.Save<clsXmlAppConfig>("appConfig.xml", currentclsXmlAppConfig);
        }


    }
}
